<template>
	<view>
		<canvas id="myCanvas" canvas-id="firstCanvas"></canvas>
		<button class="button" @click="save_but">
			保存图片
		</button>
		<view class="img">
			<image src="../static/b3.png" mode=""></image>
		</view>
	</view>
</template>

<script>
	var than;
	export default {
		data() {
			return {
				background: {
					'background': 'transparent'
				},
				title: "软件下载",
				ewm: '',
				img: ""
			}
		},
		onLoad(option) {
			than = this;
			than.img = than.img_pre + option.img
		},
		onReady: function(e) {
			than.copyFn()
		},
		methods: {
			save_but() {
				uni.showLoading();
				uni.canvasToTempFilePath({
					canvasId: 'firstCanvas',
					success: function(res) {
						uni.hideLoading()
						than.download(res.tempFilePath)
					},
					fail: function(res) {
						console.log(res);
					}
				})
			},
			copyFn() {
				let _this = this
				let c_width, h_width;
				const query = uni.createSelectorQuery().in(this);
				query.select('#myCanvas').boundingClientRect(data => { //获取canvas-dom
					c_width = data.width; //准确的宽高
					h_width = data.height
					let context = uni.createCanvasContext('firstCanvas') //绑定画布			
					context.drawImage(_this.img, 0, 0, c_width, h_width)
					context.setFontSize(11);
					context.setFillStyle('#FFFFFF') //设置内容1的文字样式
					context.draw()
				}).exec();

			},
		}
	}
</script>

<style lang="less">
	page {
		background: #FBE6BB;
	}

	#myCanvas {
		width: 588rpx;
		height: 960rpx;
		margin: auto;
	}

	.button {
		margin: 40rpx auto;
		width: 245rpx;
		height: 84rpx;
		background: #FB683D;
		border-radius: 20rpx;
		line-height: 84rpx;
		font-size: 28rpx;
		font-family: PingFang SC;
		font-weight: 500;
		color: #FFFFFF;
	}

	.img {
		text-align: center;
		padding-bottom: 20rpx;

		image {
			width: 678rpx;
			height: 232rpx;
		}
	}
</style>
